package com.yc.bank.web;

import com.yc.bank.bean.Account;
import com.yc.bank.dao.AccountDao;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "TestServlet", value = "/TestServlet")
public class TestServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        WebApplicationContext webApplicationContext =
                WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
        final AccountDao accountDao = webApplicationContext.getBean(AccountDao.class);
        final List<Account> accounts = accountDao.selectAll();
        response.getWriter().println(accounts.toString());
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
